﻿using System;
using System.Collections.Generic;
using System.Linq;
using Tauren.Business.DLL.Employee;
using Tauren.Business.Entity.Config;
using Tauren.Business.Entity.Const;
using Tauren.Business.Entity.Enum;
using Tauren.Business.Entity.Global;
using Tauren.Business.Entity.Input;
using Model = Tauren.Business.Entity.Model;
using OutPut = Tauren.Business.Entity.Output;
using Tauren.Business.DLL.AccountInfo;
using Tauren.Business.Infrastructure.Globals;
using Tauren.Business.DLL.Resouces;
using Tauren.Business.Entity.Output;
using Tauren.Business.Entity.Model;
using System.Transactions;

namespace Tauren.Business.Service.Employee
{
    /// <summary>
    /// 账户信息
    /// </summary>
    public class EmployeeService : Base.BaseService, IEmployeeService
    {

        private IEmployeeBusiness business { get; set; }
        public IAccountInfoBusiness accountBusiness { get; set; }

        public EmployeeService(IEmployeeBusiness _business, IConnectionBLLBase connectionBLL, IMenuResourcesBusiness menuResources) : base(_business, connectionBLL, menuResources)
        {
            this.ResourcesInfo = GetResources(GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY);
            this.JudePrmission(GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower());
            this.business = _business;
        }


        /// <summary>
        /// 删除人员基本信息信息
        /// </summary>
        /// </summary>
        /// <param name="model">人员基本信息实体</param>
        /// <returns></returns>
        public IResponseMessage Delete(object id)
        {
            bool b = business.Delete(id);
            if (b) RemoveRdis((int)id);
            return b.Succeed();
        }

        /// <summary>
        /// 获取人员基本信息信息--多个
        /// </summary>
        /// </summary>
        /// <param name="model">人员基本信息实体</param>
        /// <returns></returns>
        public IResponseMessage GetByCode(string code)
        {
            Model.Employee employee = business.GetByCode(code);
            OutPut.Employee_OutPut _OutPut = new OutPut.Employee_OutPut();
            ToViewModel<Model.Employee, OutPut.Employee_OutPut>(employee, out _OutPut);
            if (_OutPut != null)
            {
                _OutPut.Dic_Creator = ToSingeUserInfoName(_OutPut.Creator, Global.Language);
                _OutPut.Dic_Modifier = ToSingeUserInfoName(_OutPut.Modifier, Global.Language);
                _OutPut.OrgName = ToSingeOrgInfoName(int.Parse(_OutPut.OrgId), Global.Language);
                _OutPut.PosName = ToSingePostionInfoName(int.Parse(_OutPut.PositionId), Global.Language);
                _OutPut.PosName = ToSingePostionInfoName(int.Parse(_OutPut.PositionId), Global.Language);
                _OutPut.Dic_ReportName = ToSingeUserInfoName(_OutPut.Repoter, Global.Language);
            }
            return _OutPut.Succeed();
        }

        /// <summary>
        /// 获取人员基本信息信息--根据empids集合
        /// </summary>
        /// </summary>
        /// <param name="model">人员基本信息实体</param>
        /// <returns></returns>
        public IResponseMessage GetListByEmpIds(List<string> empids)
        {
            Dictionary<int, string> pairs = business.GetListByEmpIds(empids);
            return pairs.Succeed();
        }
        /// <summary>
        /// 获取人员基本信息信息--获取所有集合
        /// </summary>
        /// </summary>
        /// <param name="model">人员基本信息实体</param>
        /// <returns></returns>
        public IResponseMessage GetAll() => business.GetAll().Succeed();

        /// <summary>
        /// 获取单个数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IResponseMessage FirstOrDefault(object id)
        {
            Model.Employee employee = business.Get<Model.Employee>(id);
            OutPut.Employee_OutPut _OutPut = new Employee_OutPut();
            ToViewModel<Model.Employee, OutPut.Employee_OutPut>(employee, out _OutPut);
            if (_OutPut != null)
            {
                _OutPut.Dic_Creator = ToSingeUserInfoName(_OutPut.Creator, Global.Language);
                _OutPut.Dic_Modifier = ToSingeUserInfoName(_OutPut.Modifier, Global.Language);
                _OutPut.OrgName = ToSingeOrgInfoName(int.Parse(_OutPut.OrgId), Global.Language);
                _OutPut.PosName = ToSingePostionInfoName(int.Parse(_OutPut.PositionId), Global.Language);
                _OutPut.PosName = ToSingePostionInfoName(int.Parse(_OutPut.PositionId), Global.Language);
                _OutPut.Dic_ReportName = ToSingeUserInfoName(_OutPut.Repoter, Global.Language);
                Model.Employee reporter = business.Get<Model.Employee>(employee.Repoter);
                if (!(reporter is null))
                {
                    _OutPut.Reporters.Add(new PersonInfo_OutPut() { CNName = reporter.CNName, EmpId = reporter.EmpId, ENName = reporter.ENName });
                }
                var partimts = business.Parttimes(_OutPut.EmpId);
                if (partimts.Any())
                {
                    _OutPut.PartJob = partimts;
                }
            }
            else _OutPut = new Employee_OutPut();
            return _OutPut.Succeed();
        }

        public IResponseMessage All()
        {
            List<Model.Employee> employees = business.All<Model.Employee>();
            List<OutPut.Employee_OutPut> _OutPuts = new List<OutPut.Employee_OutPut>();
            ToViewModel<List<Model.Employee>, List<OutPut.Employee_OutPut>>(employees, out _OutPuts);
            if (_OutPuts.Any())
            {
                _OutPuts.ForEach(o =>
                {
                    o.Dic_Creator = EmpDictionary.ContainsKey(o.Creator) ? EmpDictionary[o.Creator] : "";
                    o.Dic_Modifier = EmpDictionary.ContainsKey(o.Modifier) ? EmpDictionary[o.Modifier] : "";
                    o.OrgName = OrgDictionary.ContainsKey(int.Parse(o.OrgId)) ? OrgDictionary[int.Parse(o.OrgId)] : "";
                    o.PosName = PosDictionary.ContainsKey(int.Parse(o.PositionId)) ? PosDictionary[int.Parse(o.PositionId)] : "";
                    o.UnitInfoName = UnitDictionary.ContainsKey(o.UnitInfoId) ? UnitDictionary[o.UnitInfoId] : "";
                    o.Dic_ReportName = EmpDictionary.ContainsKey(o.Repoter) ? EmpDictionary[o.Repoter] : "";
                });
            }
            return _OutPuts.Succeed();
        }

        /// <summary>
        /// 新增员工基本信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public IResponseMessage Add(Employee_input input)
        {
            Entity.Model.Employee model = null;
            ToModel<Entity.Model.Employee, Entity.Input.Employee_input>(input, out model);
            if (model == null)
                return ErrorType.BUSINESS_EMPLOYEE_NOTFOUND_INPUT_DATA_ERROR.Failure(this.Resources(ErrorType.BUSINESS_EMPLOYEE_NOTFOUND_INPUT_DATA_ERROR));
            model.Creatdate = DateTime.Now;
            model.Modifier = Global.EmpId;
            model.Creator = Global.EmpId;
            model.Modifdate = DateTime.Now;
            model.Status = 1;
            model.Enable = true;
            model.Sequence = business.GetSeq();
            var dbModel = business.GetByCode(model.EmpCode);
            if (dbModel == null)
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {

                        if (input.Reporters.Any())
                        {
                            model.Repoter = input.Reporters.FirstOrDefault().EmpId;
                        }
                        long id = business.Add(model);
                        if (id > 0)
                        {
                            model.EmpId = (int)id;
                            AddEmpsRdis(model);
                        }
                        if (input.PartJob.Any())
                        {
                            List<Parttimeinfo> parttimeinfos;
                            ToModel(input.PartJob, out parttimeinfos);
                            if (parttimeinfos.Any())
                            {
                                parttimeinfos.ForEach(p =>
                                {
                                    p.EmpId = model.EmpId;
                                });
                                business.Insert(parttimeinfos, model.EmpId);
                            }
                        }
                        if (id > 0)
                            ts.Complete();
                        return id.Succeed();

                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
            else return ErrorType.BUSINESS_EMPLOYEE_REPEAT_CODE.Failure(this.Resources(ErrorType.BUSINESS_EMPLOYEE_REPEAT_CODE));
        }
        /// <summary>
        /// 员工基本信息编辑
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public IResponseMessage Editor(Employee_input input)
        {
            Entity.Model.Employee model = null;
            ToModel<Entity.Model.Employee, Entity.Input.Employee_input>(input, out model);
            if (model == null)
                return ErrorType.BUSINESS_EMPLOYEE_NOTFOUND_INPUT_DATA_ERROR.Failure(this.Resources(ErrorType.BUSINESS_EMPLOYEE_NOTFOUND_INPUT_DATA_ERROR));
            model.Modifier = Global.EmpId;
            model.Modifdate = DateTime.Now;
            var dbModel = business.GetByCode(model.EmpCode);
            if (dbModel != null)
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    model.Enable = dbModel.Enable;
                    model.Status = dbModel.Status;
                    if (model.Enable && model.Status != 0)
                        AddEmpsRdis(model);
                    else RemoveRdis(model.EmpId);
                    if (input.Reporters.Any())
                    {
                        model.Repoter = input.Reporters.FirstOrDefault().EmpId;
                    }
                    bool b = business.Update(model);
                    if (b && input.PartJob.Any())
                    {
                        List<Parttimeinfo> parttimeinfos;
                        ToModel(input.PartJob, out parttimeinfos);
                        if (parttimeinfos.Any())
                        {
                            parttimeinfos.ForEach(p =>
                            {
                                p.EmpId = model.EmpId;
                            });
                        }
                        b = business.Insert(parttimeinfos, model.EmpId);
                    }
                    if (b)
                        ts.Complete();
                    return b.Succeed();
                }
            }
            else return ErrorType.BUSINESS_EMPLOYEE_DB_NOT_FOUND.Failure(this.Resources(ErrorType.BUSINESS_EMPLOYEE_DB_NOT_FOUND));
        }
        /// <summary>
        /// 分页获取数据
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        public IResponseMessage Pages(Entity.Global.QueryModel queryModel)
        {
            TableListModel<EmployeeListModel> tableListModel = new TableListModel<EmployeeListModel>();
            List<TableListHeaderModele> Headers = new List<TableListHeaderModele>();
            var PartJob = queryModel.paramters.FirstOrDefault(p => p.Label.ToLower() == OrgationalType.partjob.ToString());
            Headers.Add(new TableListHeaderModele() { Key = "rowNo", Name = this.Resources("rowno"), Width = 60, Align = "center", Fixed = true }); ;
            Headers.Add(new TableListHeaderModele() { Key = "empId", Name = this.Resources("empid"), Width = 120, Type = "primary_key", SorTable = SortType.custom.ToString(), Align = "center", Hide = true });
            Headers.Add(new TableListHeaderModele() { Key = "cnName", Name = this.Resources("cnname"), Width = 140, Type = "primary_name", SorTable = SortType.custom.ToString(), IsOperation = true, Fixed = true, Filter = true });
            Headers.Add(new TableListHeaderModele() { Key = "enName", Name = this.Resources("enname"), Width = 220, SorTable = SortType.custom.ToString(), Fixed = true, Filter = true });
            Headers.Add(new TableListHeaderModele() { Key = "empCode", Name = this.Resources("empcode"), Width = 120, SorTable = SortType.custom.ToString(), IsTag = true, Align = "center", Fixed = true, Filter = true });
            Headers.Add(new TableListHeaderModele() { Key = "unitInfoId", Name = this.Resources("unitinfoid"), Width = 120, Hide = true, SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "unitInfoName", Name = this.Resources("unitinfoname"), Width = 180, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "organizationId", Name = this.Resources("organizationid"), Width = 120, Hide = true });
            Headers.Add(new TableListHeaderModele() { Key = "organizationName", Name = this.Resources("organizationname"), Width = 160, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "positionId", Name = this.Resources("postionid"), Width = 120, Hide = true, SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "positionName", Name = this.Resources("postionname"), Width = 120, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "dic_OnPartTime", Name = this.Resources("diconparttime"), IsTag = true, Width = 100, Align = "center"});
            Headers.Add(new TableListHeaderModele() { Key = "dic_Enable", Name = CommonText("thstate"), IsTag = true, Width = 100, Align = "center", SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Creator", Name = CommonText("diccreator"), Width = 120, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Creatdate", Name = CommonText("diccreatdate"), Width = 160, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "action", Name = "操作", Width = 180, Align = "center" });
            List<EmployeeListModel> employeeListModels = new List<EmployeeListModel>();
            long Total = 0;
            List<Entity.Model.PageEployeeModel> pageEployees = business.Pages(queryModel, out Total);
            if (pageEployees.Any())
            {
                ToViewModels(pageEployees, out employeeListModels);
                employeeListModels.ForEach(o =>
                {
                    o.OrganizationName = OrgDictionary.ContainsKey(o.OrganizationId) ? OrgDictionary[o.OrganizationId] : "";
                    o.PositionName = PosDictionary.ContainsKey(o.PositionId) ? PosDictionary[o.PositionId] : "";
                    o.UnitInfoName = UnitDictionary.ContainsKey(o.UnitInfoId) ? UnitDictionary[o.UnitInfoId] : "";
                    o.Dic_OnPartTime = this.CommonText($"pt{(PartTimeJobType)o.OnPartTime}");
                    o.Row_Style = o.Enable ? "" : "danger";
                    o.Operations = new List<SystemButton>();
                    o.Dic_Enable = CommonText(o.Enable ? GlobalConst.RESOURCES_CONTENT_ENABLE_KEY : GlobalConst.RESOURCES_CONTENT_DISABLE_KEY);
                    o.Dic_Creator = EmpDictionary.ContainsKey(o.Creator) ? EmpDictionary[o.Creator] : "";
                    o.Dic_Creatdate = o.Creatdate is null ? "" : o.Creatdate.Value.ToString(GlobalConst.DATE_FORMAT_SECONDS);

                    if (Global.IsAdmin && (Buttons is null || !Buttons.Any()))
                    {
                        if (o.OnPartTime == (int)PartTimeJobType.main)
                            BuliderButtons(o.Operations, o.EmpCode, o.EmpId, ButtomType.edit);
                        BuliderButtons(o.Operations, o.EmpCode, o.EmpId, ButtomType.detaile);
                        if (o.OnPartTime == (int)PartTimeJobType.main)
                        {
                            BuliderButtons(o.Operations, o.EmpCode, o.EmpId, !o.Enable ? ButtomType.enable : ButtomType.disable);
                            BuliderButtons(o.Operations, o.EmpCode, o.EmpId, ButtomType.delete);
                        }
                    }
                    else
                    {
                        if (o.OnPartTime == (int)PartTimeJobType.main && Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && o.Value == ButtomType.edit.ToString()))
                            BuliderButtons(o.Operations, o.EmpCode, o.EmpId, ButtomType.edit);
                        if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && o.Value == ButtomType.detaile.ToString()))
                            BuliderButtons(o.Operations, o.EmpCode, o.EmpId, ButtomType.edit);
                        if (o.OnPartTime == (int)PartTimeJobType.main)
                        {
                            if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && (o.Value == ButtomType.enable.ToString() || o.Value == ButtomType.disable.ToString())))
                                BuliderButtons(o.Operations, o.EmpCode, o.EmpId, !o.Enable ? ButtomType.enable : ButtomType.disable);
                            if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && o.Value == ButtomType.delete.ToString()))
                                BuliderButtons(o.Operations, o.EmpCode, o.EmpId, ButtomType.delete);
                        }
                    }
                });
            }
            tableListModel.Body = employeeListModels;
            tableListModel.Total = Total;
            tableListModel.Header = Headers;
            if (queryModel.paramters.Any(o => o.Label.ToLower() == OrgationalType.position.ToString())|| queryModel.KeyWords.Any(o => o.Label.ToLower() == OrgationalType.position.ToString()))
            {
                if (Global.IsAdmin && (Buttons is null || !Buttons.Any()))
                {
                    BuliderButtons(tableListModel.Operations, "", 0, ButtomType.add);
                }
                else
                {
                    if (Buttons.Any(o => o.Value == ButtomType.add.ToString()))
                        BuliderButtons(tableListModel.Operations, "", 0, ButtomType.add);
                }
            }
            return tableListModel.Succeed();
        }
        /// <summary>
        /// 将员工添加到redis
        /// </summary>
        /// <param name="model"></param>
        private void AddEmpsRdis(Entity.Model.Employee model)
        {
            string redisKey = $"{Global.TenementCode.ToUpper()}_{GlobalConst.EMPLOYEE_FLAG_REDIS_KEY}";
            string redisHashField = $"{redisKey}_{model.EmpId}";
            if (!RedisClient.HashKeys(redisKey).Any())
            {
                ToUserInfos();
            }
            else
            {
                RedisClient.HashDelete(redisKey, redisHashField);
                RedisClient.HashSet(redisKey, redisHashField, model);
            }
        }
        /// <summary>
        /// 将员工从redis中移除
        /// </summary>
        /// <param name="model"></param>
        private void RemoveRdis(int ID)
        {
            string redisKey = $"{Global.TenementCode.ToUpper()}_{GlobalConst.EMPLOYEE_FLAG_REDIS_KEY}";
            string redisHashField = $"{redisKey}_{ID}";
            RedisClient.HashDelete(redisKey, redisHashField);
        }

        public IResponseMessage PhysicalDelete(int id)
        {
            bool b = business.PhysicalDelete(id);
            if (b) RemoveRdis((int)id);
            return b.Succeed();
        }

        public IResponseMessage Enable(int id)
        {
            Model.Employee employee = business.Get<Model.Employee>(id);
            if (employee == null) return ErrorType.BUSINESS_EMPLOYEE_DB_NOT_FOUND.Failure(this.Resources(ErrorType.BUSINESS_EMPLOYEE_DB_NOT_FOUND));
            employee.Enable = !employee.Enable;
            employee.Modifdate = DateTime.Now;
            employee.Modifier = Global.EmpId;
            bool b = business.Update<Model.Employee>(employee);
            if (b) RemoveRdis((int)id);
            return b.Succeed();
        }

        /// <summary>
        /// 根据组织获取员工基本信息
        /// </summary>
        /// <param name="OrgId"></param>
        /// <returns></returns>
        public IResponseMessage GetByOrgs(string OrgId)
        {
            List<Model.Employee> employees = business.GetByOrgs(OrgId);
            List<OutPut.Employee_OutPut> _OutPuts = new List<OutPut.Employee_OutPut>();
            ToViewModel(employees, out _OutPuts);
            if (_OutPuts.Any())
            {
                _OutPuts.ForEach(o =>
                {
                    o.Dic_Creator = EmpDictionary.ContainsKey(o.Creator) ? EmpDictionary[o.Creator] : "";
                    o.Dic_Modifier = EmpDictionary.ContainsKey(o.Modifier) ? EmpDictionary[o.Modifier] : "";
                    o.OrgName = OrgDictionary.ContainsKey(int.Parse(o.OrgId)) ? OrgDictionary[int.Parse(o.OrgId)] : "";
                    o.PosName = PosDictionary.ContainsKey(int.Parse(o.PositionId)) ? PosDictionary[int.Parse(o.PositionId)] : "";
                    o.UnitInfoName = UnitDictionary.ContainsKey(o.UnitInfoId) ? UnitDictionary[o.UnitInfoId] : "";
                    o.Dic_ReportName = EmpDictionary.ContainsKey(o.Repoter) ? EmpDictionary[o.Repoter] : "";
                });
            }
            return _OutPuts.Succeed();
        }

        /// <summary>
        /// 根据接口获取当前用户
        /// </summary>
        /// <returns></returns>
        public IResponseMessage GetCurrentUser()
        {
            OutPut.GlobalModel_OutPut _OutPut = null;
            ToViewModel(this.Global, out _OutPut);
            var model = accountBusiness.Get<Model.AccoutInfo>(this.Global.UserId);
            if (model != null)
            {
                model.Language = Global.IsChinese ? "zh-cn" : "en";
                accountBusiness.Update<Model.AccoutInfo>(model);
            }
            return _OutPut.Succeed();
        }

        public IResponseMessage Tree()
        {

            List<Entity.Model.Unitinfo> Companys = baseDLL.All<Entity.Model.Unitinfo>();
            List<Entity.Model.Organization> Organizations = baseDLL.All<Entity.Model.Organization>();
            List<Position> Positions = baseDLL.All<Position>();
            List<GlobalTree> globalTrees = new List<GlobalTree>();
            Companys.Where(o => o.ParentId == 0 && !o.HaveDelete).ToList().ForEach(o =>
            {
                globalTrees.Add(new GlobalTree()
                {
                    Icon = "el-icon-lx-shop",
                    Id = o.UnitId,
                    Label = Global.Language == (LanguageType.zh_cn.ToString().Replace("_", "-")) ? o.CNName : string.IsNullOrEmpty(o.ENName) ? o.CNName : o.ENName,
                    Code = o.UnitCode,
                    CNName = o.CNName,
                    ENName = o.ENName,
                    ParentId = o.ParentId.Value,
                    Children = GenerateChildUnitTreeInfo(o.UnitId, Companys, Organizations, Positions),
                    UseNodeCss = !o.Enable || o.HaveDelete,
                    NodeType = OrgationalType.unit.ToString()
                });
            });
            return globalTrees.Succeed();
        }
        private List<GlobalTree> GenerateChildUnitTreeInfo(int ParentId, List<Unitinfo> companys, List<Organization> organizations, List<Position> Positions)
        {
            List<GlobalTree> _OutPuts = new List<GlobalTree>();
            List<Unitinfo> childMenus = companys.Where(o => !o.HaveDelete && o.ParentId == ParentId && !o.HaveDelete).ToList();
            if (childMenus.Any())
            {
                childMenus.ForEach(o =>
                {
                    _OutPuts.Add(new GlobalTree()
                    {
                        Icon = "el-icon-lx-shop",
                        Id = o.UnitId,
                        Label = Global.Language == (LanguageType.zh_cn.ToString().Replace("_", "-")) ? o.CNName : string.IsNullOrEmpty(o.ENName) ? o.CNName : o.ENName,
                        Code = o.UnitCode,
                        CNName = o.CNName,
                        ENName = o.ENName,
                        ParentId = o.ParentId.Value,
                        Children = GenerateChildUnitTreeInfo(o.UnitId, companys, organizations, Positions),
                        UseNodeCss = !o.Enable || o.HaveDelete,
                        NodeType = OrgationalType.unit.ToString()
                    });
                });
            }
            List<Organization> orgs = organizations.Where(o => o.ParentId == 0 && o.UnitId == ParentId && !o.HaveDelete).ToList();
            if (orgs.Any())
            {
                orgs.ForEach(o =>
                {
                    _OutPuts.Add(new GlobalTree()
                    {
                        Icon = "el-icon-office-building",
                        Id = o.OrgId,
                        Label = Global.Language == (LanguageType.zh_cn.ToString().Replace("_", "-")) ? o.CNName : string.IsNullOrEmpty(o.ENName) ? o.CNName : o.ENName,
                        Code = o.OrgCode,
                        CNName = o.CNName,
                        ENName = o.ENName,
                        ParentId = o.ParentId.Value,
                        Children = GenerateChildOrgTreeInfo(o, organizations, Positions),
                        NodeType = OrgationalType.organization.ToString(),
                        Parameters = new List<Options>() { new Entity.Output.Options() { Label = "companyId", Value = o.UnitId } }
                    });
                });
            }
            List<Position> pos = Positions.Where(o => o.OrgType == OrgationalType.unit.ToString() && o.OrgId.Value == ParentId && !o.HaveDelete).ToList();
            if (pos.Any())
            {
                pos.ForEach(o =>
                {
                    _OutPuts.Add(new GlobalTree()
                    {
                        Icon = "el-icon-table-lamp",
                        Id = o.PositionId,
                        Label = Global.Language == (LanguageType.zh_cn.ToString().Replace("_", "-")) ? o.CNName : string.IsNullOrEmpty(o.ENName) ? o.CNName : o.ENName,
                        Code = o.PositionCode,
                        CNName = o.CNName,
                        ENName = o.ENName,
                        ParentId = o.ParentId,
                        NodeType = OrgationalType.position.ToString(),
                        Parameters = new List<Options>() { new Entity.Output.Options() { Label = "companyId", Value = o.OrgId } }
                    });
                });
            }
            return _OutPuts;
        }

        private List<GlobalTree> GenerateChildOrgTreeInfo(Organization organization, List<Organization> organizations, List<Position> Positions)
        {
            List<GlobalTree> _OutPuts = new List<GlobalTree>();
            List<Organization> orgs = organizations.Where(o => o.ParentId == organization.OrgId && !o.HaveDelete).ToList();
            if (orgs.Any())
            {
                orgs.ForEach(o =>
                {
                    _OutPuts.Add(new GlobalTree()
                    {
                        Icon = "el-icon-office-building",
                        Id = o.OrgId,
                        Label = Global.Language == (LanguageType.zh_cn.ToString().Replace("_", "-")) ? o.CNName : string.IsNullOrEmpty(o.ENName) ? o.CNName : o.ENName,
                        Code = o.OrgCode,
                        CNName = o.CNName,
                        ENName = o.ENName,
                        ParentId = o.ParentId.Value,
                        Children = GenerateChildOrgTreeInfo(o, organizations, Positions),
                        UseNodeCss = !o.Enable || o.HaveDelete,
                        NodeType = OrgationalType.organization.ToString(),
                        Parameters = new List<Options>() { new Entity.Output.Options() { Label = "companyId", Value = o.UnitId.Value } }
                    });
                });
            }
            List<Position> pos = Positions.Where(o => o.OrgType == OrgationalType.organization.ToString() && o.OrgId.Value == organization.OrgId && !o.HaveDelete).ToList();
            if (pos.Any())
            {
                pos.ForEach(o =>
                {
                    _OutPuts.Add(new GlobalTree()
                    {
                        Icon = "el-icon-table-lamp",
                        Id = o.PositionId,
                        Label = Global.Language == (LanguageType.zh_cn.ToString().Replace("_", "-")) ? o.CNName : string.IsNullOrEmpty(o.ENName) ? o.CNName : o.ENName,
                        Code = o.PositionCode,
                        CNName = o.CNName,
                        ENName = o.ENName,
                        ParentId = o.ParentId,
                        NodeType = OrgationalType.position.ToString(),
                        Parameters = new List<Options>() { new Entity.Output.Options() { Label = "companyId", Value = organization.UnitId }, new Options() { Label = "orgId", Value = organization.OrgId } }
                    });
                });
            }
            return _OutPuts;
        }

        public IResponseMessage Config(string PageType)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            List<OutPutConfig> Fields = new List<OutPutConfig>();

            OutPutConfig config = new OutPutConfig();

            #region 头像
            config = new OutPutConfig();
            config.Label = this.Resources("empavatar");
            config.FieldKey = "empAvatar";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower();
            config.ControlType = ControlType.avatar;
            config.Show = true;
            config.Editor = PageType != "view";
            Fields.Add(config);

            #endregion
            config = new OutPutConfig();
            config.Label = this.Resources("empcode");
            config.FieldKey = "empCode";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower();
            config.ControlType = ControlType.text;
            config.Show = true;
            config.Editor = PageType != "view" && PageType != "edit";
            config.Required = PageType != "view" && PageType != "edit";
            Dictionary<object, object> rule = new Dictionary<object, object>();
            if (PageType != "view")
            {
                #region 添加验证规则

                rule.Add("required", true);
                rule.Add("message", this.Resources("empcoderequired"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///长度
                rule = new Dictionary<object, object>();
                rule.Add("min", 1);
                rule.Add("max", 20);
                rule.Add("message", this.Resources("empcodemax"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///正则
                rule = new Dictionary<object, object>();
                rule.Add("pattern", "^([a-zA-Z0-9_]){1,20}$");
                rule.Add("message", this.Resources("empcoderegx"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
            }
            Fields.Add(config);
            #endregion
            #region 中文名
            config = new OutPutConfig();
            config.Label = this.CommonText("thcnname");
            config.FieldKey = "cnName";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower();
            config.ControlType = ControlType.textarea;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            rule = new Dictionary<object, object>();
            if (PageType != "view")
            {
                rule.Add("required", true);
                rule.Add("message", this.Resources("cnnamerequired"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///长度
                rule = new Dictionary<object, object>();
                rule.Add("min", 1);
                rule.Add("max", 100);
                rule.Add("message", this.Resources("cnnamemax"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
            }
            Fields.Add(config);
            #endregion

            #region 英文名
            config = new OutPutConfig();
            config.Label = this.CommonText("thenname");
            config.FieldKey = "enName";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower();
            config.ControlType = ControlType.textarea;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            rule = new Dictionary<object, object>();
            if (PageType != "view")
            {
                rule.Add("required", true);
                rule.Add("message", this.Resources("ennamerequired"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///长度
                rule = new Dictionary<object, object>();
                rule.Add("min", 1);
                rule.Add("max", 200);
                rule.Add("message", this.Resources("ennamemax"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
            }
            Fields.Add(config);
            #endregion

            #region 性别
            config = new OutPutConfig();
            config.Label = this.Resources("thegender");
            config.FieldKey = "gender";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower();
            config.ControlType = ControlType.parameter;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            config.Options = new List<Options>()
            {
                new Options(){Label=this.Resources($"th{Gender.male}"),Value=Gender.male.ToString()},
                new Options(){Label=this.Resources($"th{Gender.female}"),Value=Gender.female.ToString()}
            };
            Fields.Add(config);
            #endregion

            #region 年龄
            config = new OutPutConfig();
            config.Label = this.Resources("theage");
            config.FieldKey = "age";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower();
            config.ControlType = ControlType.text;
            if (PageType != "view")
            {
                rule = new Dictionary<object, object>();
                rule.Add("pattern", "^([0-9]{1,2}|100)$");
                rule.Add("message", this.Resources("ageregx"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
            }
            config.Show = true;
            config.Editor = PageType != "view";
            Fields.Add(config);
            #endregion
            #region 证件号
            config = new OutPutConfig();
            config.Label = this.CommonText("thidcard");
            config.FieldKey = "idCard";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower();
            config.ControlType = ControlType.text;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            config.Show = true;
            config.Editor = PageType != "view";
            Fields.Add(config);
            #endregion
            #region 生日
            config = new OutPutConfig();
            config.Label = this.Resources("thbirthday");
            config.FieldKey = "birthDay";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower();
            config.ControlType = ControlType.date;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            config.Show = true;
            config.Editor = PageType != "view";
            Fields.Add(config);
            #endregion

            #region 入职日期
            config = new OutPutConfig();
            config.Label = this.Resources("thjoindate");
            config.FieldKey = "joinDate";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower();
            config.ControlType = ControlType.date;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            config.Show = true;
            config.Editor = PageType != "view";
            Fields.Add(config);
            #endregion

            #region 邮箱
            config = new OutPutConfig();
            config.Label = this.Resources("themail");
            config.FieldKey = "enName";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower();
            config.ControlType = ControlType.textarea;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            rule = new Dictionary<object, object>();
            if (PageType != "view")
            {

                rule.Add("required", true);
                rule.Add("message", this.Resources("emailquired"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///长度
                rule = new Dictionary<object, object>();
                rule.Add("min", 1);
                rule.Add("max", 30);
                rule.Add("message", this.Resources("emailmax"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///正则
                rule = new Dictionary<object, object>();
                rule.Add("pattern", @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
                rule.Add("message", this.Resources("emailregx"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
            }
            #endregion
            #region 移动电话
            config = new OutPutConfig();
            config.Label = this.Resources("thphone");
            config.FieldKey = "enName";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower();
            config.ControlType = ControlType.textarea;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            rule = new Dictionary<object, object>();
            if (PageType != "view")
            {
                ///正则
                rule = new Dictionary<object, object>();
                rule.Add("pattern", @"^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$");
                rule.Add("message", this.Resources("phoneregx"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
            }
            #endregion

            ///兼职
            config = new OutPutConfig();
            config.Label = this.Resources("thpartjob");
            config.FieldKey = "partJob";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower();
            config.ControlType = ControlType.position;
            config.Show = true;
            config.Editor = PageType != "view";
            config.SelectType = SelectType.multi;
            BuliedTableConfig(config.Tables, PageType, new List<FromTableHeader>() { new FromTableHeader { FieldKey = "positionId", Show = false, Primary = true }, new FromTableHeader { FieldKey = "cnName" }, new FromTableHeader { FieldKey = "enName", } }, config.Operations);
            config.ExceptDataField = new List<Options>() { new Options() { Label = "positionId", Value = 0 } };
            Fields.Add(config);

            ///汇报人
            config = new OutPutConfig();
            config.FieldKey = "reporters";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower();
            config.ControlType = ControlType.employee;
            config.Label = this.Resources("threporters");
            config.Show = true;
            config.Editor = PageType != "view";
            config.SelectType = SelectType.radio;
            BuliedTableConfig(config.Tables, PageType, new List<FromTableHeader>() { new FromTableHeader { FieldKey = "empId", Show = false, Primary = true }, new FromTableHeader { FieldKey = "cnName" }, new FromTableHeader { FieldKey = "enName", } }, config.Operations);
            config.ExceptDataField = new List<Options>() { new Options() { Label = "empId", Value = 0 } };
            Fields.Add(config);
            #region 入职日期
            config = new OutPutConfig();
            config.Label = this.Resources("thaddress");
            config.FieldKey = "address";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_EMPLOYEE_KEY.ToLower();
            config.ControlType = ControlType.textarea;
            config.Show = true;
            config.Editor = PageType != "view";
            Fields.Add(config);
            #endregion
            return Fields.Succeed();
        }

        /// <summary>
        /// 弹出人员列表
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        public IResponseMessage DialogEmps(QueryModel queryModel)
        {
            TableListModel<EmployeeListModel> tableListModel = new TableListModel<EmployeeListModel>();
            List<TableListHeaderModele> Headers = new List<TableListHeaderModele>();
            var PartJob = queryModel.paramters.FirstOrDefault(p => p.Label.ToLower() == OrgationalType.partjob.ToString());
            Headers.Add(new TableListHeaderModele() { Key = "rowNo", Name = this.Resources("rowno"), Width = 60, Align = "center", Fixed = true }); ;
            Headers.Add(new TableListHeaderModele() { Key = "empId", Name = this.Resources("empid"), Width = 120, Type = "primary_key", SorTable = SortType.custom.ToString(), Align = "center", Hide = true });
            Headers.Add(new TableListHeaderModele() { Key = "cnName", Name = this.Resources("cnname"), Width = 140, Type = "primary_name", SorTable = SortType.custom.ToString(), IsOperation = true, IsTag = true, Fixed = true });
            Headers.Add(new TableListHeaderModele() { Key = "enName", Name = this.Resources("enname"), Width = 220, SorTable = SortType.custom.ToString(), Fixed = true });
            Headers.Add(new TableListHeaderModele() { Key = "empCode", Name = this.Resources("empcode"), Width = 120, SorTable = SortType.custom.ToString(), IsTag = true, Align = "center", Fixed = true });
            Headers.Add(new TableListHeaderModele() { Key = "unitInfoId", Name = this.Resources("unitinfoid"), Width = 120, Hide = true, SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "unitInfoName", Name = this.Resources("unitinfoname"), Width = 180, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "organizationId", Name = this.Resources("organizationid"), Width = 120, Hide = true });
            Headers.Add(new TableListHeaderModele() { Key = "organizationName", Name = this.Resources("organizationname"), Width = 120, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "positionId", Name = this.Resources("postionid"), Width = 120, Hide = true, SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "positionName", Name = this.Resources("postionname"), Width = 120, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "dic_OnPartTime", Name = this.Resources("diconparttime"), IsTag = true, Width = 100, Align = "center", Fixed = true });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Enable", Name = CommonText("thstate"), IsTag = true, Width = 100, Align = "center", SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Creator", Name = CommonText("diccreator"), Width = 120, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Creatdate", Name = CommonText("diccreatdate"), Width = 160, Align = "center" });
            List<EmployeeListModel> employeeListModels = new List<EmployeeListModel>();
            long Total = 0;
            List<Entity.Model.PageEployeeModel> pageEployees = business.DialogPages(queryModel, out Total);
            if (pageEployees.Any())
            {
                ToViewModels(pageEployees, out employeeListModels);
                employeeListModels.ForEach(o =>
                {
                    o.OrganizationName = OrgDictionary.ContainsKey(o.OrganizationId) ? OrgDictionary[o.OrganizationId] : "";
                    o.PositionName = PosDictionary.ContainsKey(o.PositionId) ? PosDictionary[o.PositionId] : "";
                    o.UnitInfoName = UnitDictionary.ContainsKey(o.UnitInfoId) ? UnitDictionary[o.UnitInfoId] : "";
                    o.Dic_OnPartTime = this.CommonText($"pt{(PartTimeJobType)o.OnPartTime}");
                    o.Row_Style = o.Enable ? "" : "danger";
                    o.Operations = new List<SystemButton>();
                    o.Dic_Enable = CommonText(o.Enable ? GlobalConst.RESOURCES_CONTENT_ENABLE_KEY : GlobalConst.RESOURCES_CONTENT_DISABLE_KEY);
                    o.Dic_Creator = EmpDictionary.ContainsKey(o.Creator) ? EmpDictionary[o.Creator] : "";
                    o.Dic_Creatdate = o.Creatdate is null ? "" : o.Creatdate.Value.ToString(GlobalConst.DATE_FORMAT_SECONDS);

                    if (Global.IsAdmin && (Buttons is null || !Buttons.Any()))
                    {
                        if (o.OnPartTime == (int)PartTimeJobType.main)
                            BuliderButtons(o.Operations, o.EmpCode, o.EmpId, ButtomType.edit);
                        BuliderButtons(o.Operations, o.EmpCode, o.EmpId, ButtomType.detaile);
                        if (o.OnPartTime == (int)PartTimeJobType.main)
                        {
                            BuliderButtons(o.Operations, o.EmpCode, o.EmpId, !o.Enable ? ButtomType.enable : ButtomType.disable);
                            BuliderButtons(o.Operations, o.EmpCode, o.EmpId, ButtomType.delete);
                        }
                    }
                    else
                    {
                        Buttons.Where(o => o.Location == ButtomLocation.center.ToString() && o.Value != ButtomType.add.ToString()).ToList().ForEach(p =>
                        {
                            o.Operations.Add(new SystemButton() { Label = p.Label, Location = ButtomLocation.center.ToString(), Icon = p.Icon, KeyFieldValue = o.EmpCode, PrimaryKeyValue = o.EmpId, Shape = p.Shape, Size = p.Size, Type = "text", Value = p.Value });
                        });
                        if (o.OnPartTime == (int)PartTimeJobType.main)
                        {
                            Buttons = Buttons.Where(p => p.Label == ButtomType.detaile.ToString()).ToList();
                        }
                    }
                });
            }
            tableListModel.Body = employeeListModels;
            tableListModel.Total = Total;
            tableListModel.Header = Headers;
            if (queryModel.paramters.Any(o => o.Label.ToLower() == OrgationalType.position.ToString()))
            {
                if (Global.IsAdmin && (Buttons is null || !Buttons.Any()))
                {
                    BuliderButtons(tableListModel.Operations, "", 0, ButtomType.add, BtnShapeType.plain.ToString());
                }
                else
                {
                    Buttons.Where(o => o.Location != ButtomLocation.center.ToString()).ToList().ForEach(p =>
                    {
                        tableListModel.Operations.Add(new SystemButton() { Label = p.Label, Location = ButtomLocation.top.ToString(), Icon = p.Icon, Shape = BtnShapeType.plain.ToString(), Size = p.Size, Type = p.Type, Value = p.Value });
                    });
                }
            }
            return tableListModel.Succeed();
        }

        /// <summary>
        /// 流程任务审批人列表
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        public IResponseMessage FlowEmps(QueryModel queryModel)
        {
            TableListModel<EmployeeListModel> tableListModel = new TableListModel<EmployeeListModel>();
            List<TableListHeaderModele> Headers = new List<TableListHeaderModele>();
            var PartJob = queryModel.paramters.FirstOrDefault(p => p.Label.ToLower() == OrgationalType.partjob.ToString());
            Headers.Add(new TableListHeaderModele() { Key = "rowNo", Name = this.Resources("rowno"), Width = 60, Align = "center", Fixed = true }); ;
            Headers.Add(new TableListHeaderModele() { Key = "empId", Name = this.Resources("empid"), Width = 120, Type = "primary_key", SorTable = SortType.custom.ToString(), Align = "center", Hide = true });
            Headers.Add(new TableListHeaderModele() { Key = "cnName", Name = this.Resources("cnname"), Width = 140, Type = "primary_name", SorTable = SortType.custom.ToString(), IsOperation = true, IsTag = true, Fixed = true });
            Headers.Add(new TableListHeaderModele() { Key = "enName", Name = this.Resources("enname"), Width = 220, SorTable = SortType.custom.ToString(), Fixed = true });
            Headers.Add(new TableListHeaderModele() { Key = "empCode", Name = this.Resources("empcode"), Width = 120, SorTable = SortType.custom.ToString(), IsTag = true, Align = "center", Fixed = true });
            Headers.Add(new TableListHeaderModele() { Key = "unitInfoId", Name = this.Resources("unitinfoid"), Width = 120, Hide = true, SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "unitInfoName", Name = this.Resources("unitinfoname"), Width = 180, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "organizationId", Name = this.Resources("organizationid"), Width = 120, Hide = true });
            Headers.Add(new TableListHeaderModele() { Key = "organizationName", Name = this.Resources("organizationname"), Width = 120, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "positionId", Name = this.Resources("postionid"), Width = 120, Hide = true, SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "positionName", Name = this.Resources("postionname"), Width = 120, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "dic_OnPartTime", Name = this.Resources("diconparttime"), IsTag = true, Width = 100, Align = "center", Fixed = true });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Enable", Name = CommonText("thstate"), IsTag = true, Width = 100, Align = "center", SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Creator", Name = CommonText("diccreator"), Width = 120, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Creatdate", Name = CommonText("diccreatdate"), Width = 160, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "action", Name = "操作", Width = 160, Align = "center" });
            List<EmployeeListModel> employeeListModels = new List<EmployeeListModel>();
            long Total = 0;
            List<Entity.Model.PageEployeeModel> pageEployees = business.FlowApproverPages(queryModel, out Total);
            if (pageEployees.Any())
            {
                ToViewModels(pageEployees, out employeeListModels);
                employeeListModels.ForEach(o =>
                {
                    o.OrganizationName = OrgDictionary.ContainsKey(o.OrganizationId) ? OrgDictionary[o.OrganizationId] : "";
                    o.PositionName = PosDictionary.ContainsKey(o.PositionId) ? PosDictionary[o.PositionId] : "";
                    o.UnitInfoName = UnitDictionary.ContainsKey(o.UnitInfoId) ? UnitDictionary[o.UnitInfoId] : "";
                    o.Dic_OnPartTime = this.CommonText($"pt{(PartTimeJobType)o.OnPartTime}");
                    o.Row_Style = o.Enable ? "" : "danger";
                    o.Operations = new List<SystemButton>();
                    o.Dic_Enable = CommonText(o.Enable ? GlobalConst.RESOURCES_CONTENT_ENABLE_KEY : GlobalConst.RESOURCES_CONTENT_DISABLE_KEY);
                    o.Dic_Creator = EmpDictionary.ContainsKey(o.Creator) ? EmpDictionary[o.Creator] : "";
                    o.Dic_Creatdate = o.Creatdate is null ? "" : o.Creatdate.Value.ToString(GlobalConst.DATE_FORMAT_SECONDS);

                    if (Global.IsAdmin && (Buttons is null || !Buttons.Any()))
                    {
                        if (o.OnPartTime == (int)PartTimeJobType.main)
                            BuliderButtons(o.Operations, o.EmpCode, o.EmpId, ButtomType.edit);
                        BuliderButtons(o.Operations, o.EmpCode, o.EmpId, ButtomType.detaile);
                        if (o.OnPartTime == (int)PartTimeJobType.main)
                        {
                            BuliderButtons(o.Operations, o.EmpCode, o.EmpId, !o.Enable ? ButtomType.enable : ButtomType.disable);
                            BuliderButtons(o.Operations, o.EmpCode, o.EmpId, ButtomType.delete);
                        }
                    }
                    else
                    {
                        Buttons.Where(o => o.Location == ButtomLocation.center.ToString() && o.Value != ButtomType.add.ToString()).ToList().ForEach(p =>
                        {
                            o.Operations.Add(new SystemButton() { Label = p.Label, Location = ButtomLocation.center.ToString(), Icon = p.Icon, KeyFieldValue = o.EmpCode, PrimaryKeyValue = o.EmpId, Shape = p.Shape, Size = p.Size, Type = "text", Value = p.Value });
                        });
                        if (o.OnPartTime == (int)PartTimeJobType.main)
                        {
                            Buttons = Buttons.Where(p => p.Label == ButtomType.detaile.ToString()).ToList();
                        }
                    }
                });
            }
            tableListModel.Body = employeeListModels;
            tableListModel.Total = Total;
            tableListModel.Header = Headers;
            if (queryModel.paramters.Any(o => o.Label.ToLower() == OrgationalType.position.ToString()))
            {
                if (Global.IsAdmin && (Buttons is null || !Buttons.Any()))
                {
                    BuliderButtons(tableListModel.Operations, "", 0, ButtomType.add, BtnShapeType.plain.ToString());
                }
                else
                {
                    Buttons.Where(o => o.Location != ButtomLocation.center.ToString()).ToList().ForEach(p =>
                    {
                        tableListModel.Operations.Add(new SystemButton() { Label = p.Label, Location = ButtomLocation.top.ToString(), Icon = p.Icon, Shape = BtnShapeType.plain.ToString(), Size = p.Size, Type = p.Type, Value = p.Value });
                    });
                }
            }
            return tableListModel.Succeed();
        }
    }
}
